package com.kefu.call.utils;

import cn.hutool.core.date.DateUtil;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.util.CellRangeAddress;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

public class DateWeekEndUtil {
    public static Map<Integer, Long> getWeekData(Long time) {
        Map<Integer, Long> map = new HashMap<>();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
        Calendar cld = Calendar.getInstance(Locale.CHINA);
        cld.setFirstDayOfWeek(Calendar.MONDAY);//以周一为首日
        cld.setTimeInMillis(time);//当前时间
        cld.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);//周一
        map.put(1, DateUtil.beginOfDay(cld.getTime()).getTime());
//        currentMondy = df.format(cld.getTime()).substring(5,7)+"月"+df.format(cld.getTime()).substring(8)+"日";
        cld.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);//周日
//        currentSunday =df.format(cld.getTime()).substring(5,7)+"月"+ df.format(cld.getTime()).substring(8)+"日";
//        Console.log(currentMondy);
//        Console.log(currentSunday + ":" + (DateUtil.endOfDay(cld.getTime()).getTime() + 1));
        map.put(2, DateUtil.endOfDay(cld.getTime()).getTime());
        return map;
    }

    public static void main(String[] args) throws IOException {

        HSSFWorkbook workbook = new HSSFWorkbook();

        HSSFCellStyle style = workbook.createCellStyle();
        style.setAlignment(HorizontalAlignment.CENTER);
        style.setVerticalAlignment(VerticalAlignment.CENTER);

        HSSFSheet sheet = workbook.createSheet("sheet");
        sheet.setColumnWidth(0, 20 * 256);

        HSSFRow row0 = sheet.createRow(0);
        HSSFCell cell_00 = row0.createCell(0);
        cell_00.setCellStyle(style);
        cell_00.setCellValue("日期");
        row0.setHeight((short) 500);

        HSSFCell cell_01 = row0.createCell(1);
        cell_01.setCellStyle(style);
        cell_01.setCellValue("平台类型");

        HSSFCell cell_02 = row0.createCell(2);
        cell_02.setCellStyle(style);
        cell_02.setCellValue("问题数量");

        HSSFCell cell_07 = row0.createCell(7);
        cell_07.setCellStyle(style);
        cell_07.setCellValue("一线解决数量");
        HSSFCell cell_08 = row0.createCell(8);
        cell_08.setCellStyle(style);
        cell_08.setCellValue("转二线数量");
        HSSFCell cell_09 = row0.createCell(9);
        cell_09.setCellStyle(style);
        cell_09.setCellValue("转二线解决数量");
        HSSFCell cell_010 = row0.createCell(10);
        cell_010.setCellStyle(style);
        cell_010.setCellValue("待解决数量");


        HSSFRow row = sheet.createRow(1);
        row.setHeight((short) 500);
        HSSFCell cell_2 = row.createCell(2);
        cell_2.setCellStyle(style);
        cell_2.setCellValue("使用问题");
        HSSFCell cell_3 = row.createCell(3);
        cell_3.setCellStyle(style);
        cell_3.setCellValue("故障bug");
        HSSFCell cell_4 = row.createCell(4);
        cell_4.setCellStyle(style);
        cell_4.setCellValue("需求优化");
        HSSFCell cell_5 = row.createCell(5);
        cell_5.setCellStyle(style);
        cell_5.setCellValue("商务合作");
        HSSFCell cell_6 = row.createCell(6);
        cell_6.setCellStyle(style);
        cell_6.setCellValue("问题数量");
        CellRangeAddress region = new CellRangeAddress(0, 1, 0, 0);
        sheet.addMergedRegion(region);

        CellRangeAddress region_1 = new CellRangeAddress(0, 1, 1, 1);
        sheet.addMergedRegion(region_1);

        CellRangeAddress region_2 = new CellRangeAddress(0, 0, 2, 6);
        sheet.addMergedRegion(region_2);

        for (int i = 2; i < 10;) {
            HSSFRow row1 = sheet.createRow(i);
            HSSFCell cell_10 = row1.createCell(0);
            cell_10.setCellStyle(style);
            cell_10.setCellValue("2018-04-12");

            HSSFCell cell_11 = row1.createCell(1);
            cell_11.setCellStyle(style);
            cell_11.setCellValue("商密网");

            HSSFRow row2 = sheet.createRow(i+1);
            HSSFCell cell_21 = row2.createCell(1);
            cell_21.setCellStyle(style);
            cell_21.setCellValue("航天云网平台");

            HSSFRow row3 = sheet.createRow(i+2);
            HSSFCell cell_31 = row3.createCell(1);
            cell_31.setCellStyle(style);
            cell_31.setCellValue("其他");
            // 合并日期占两行(4个参数，分别为起始行，结束行，起始列，结束列)
            // 行和列都是从0开始计数，且起始结束都会合并
            // 这里是合并excel中日期的两行为一行
            int a = i;
            int b = i +2;
            CellRangeAddress region1 = new CellRangeAddress(a, b, 0, 0);
            sheet.addMergedRegion(region1);
            i = i+3;
        }

//
//        HSSFRow row3 = sheet.createRow(3);
//        HSSFCell cell_30 = row3.createCell(0);
//        cell_30.setCellStyle(style);
//        cell_30.setCellValue("2018-04-12");
//
//        HSSFCell cell_31 = row3.createCell(1);
//        cell_31.setCellStyle(style);
//        cell_31.setCellValue("上午");
//
//        HSSFRow row4 = sheet.createRow(4);
//        HSSFCell cell_41 = row4.createCell(1);
//        cell_41.setCellStyle(style);
//        cell_41.setCellValue("下午");
//        // 合并日期占两行(4个参数，分别为起始行，结束行，起始列，结束列)
//        // 行和列都是从0开始计数，且起始结束都会合并
//        // 这里是合并excel中日期的两行为一行
//        CellRangeAddress region1 = new CellRangeAddress(3, 4, 0, 0);
//        sheet.addMergedRegion(region1);


        File file = new File("D:\\demo.xls");
        FileOutputStream fout = new FileOutputStream(file);
        workbook.write(fout);
        fout.close();
    }
}
